import Vue from 'vue'
import App from './App.vue'
import router from "./router"
import store from "./store/index.js"

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);

Vue.config.productionTip = false
let instance = null

function render(){
  instance = new Vue({
    store,
    router,
    render: h => h(App),
  }).$mount('#app-31')
}

if (window.__POWERED_BY_QIANKUN__) { // 动态添加publicPath
  __webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
}
if (!window.__POWERED_BY_QIANKUN__) { // 默认独立运行
  render();
}
 
// 父应用加载子应用，子应用必须暴露三个接口：bootstrap、mount、unmount
// 子组件的协议就ok了
export async function bootstrap(props) {
  console.log(" bootstrap 31 props:",props)
};

export async function mount(props) {
  console.log(" mount 31 props:",props)
  props.onGlobalStateChange((state, prevState)=>{
    console.log(' mount 31 state:',state)
    console.log(' mount 31 prevState:',prevState)
    store.commit('setToken',state.globalToken)
  })
  render(props)
}

export async function unmount(props) {
  instance.$destroy();
}